Skip to content

feat: include reason label to kube_deployment_status_condition #2719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Rishab87
Copy link
Contributor

@Rishab87 Rishab87 commented Aug 4, 2025

What this PR does / why we need it:
Building upon the work of #2146, I've addressed the reviews and created this.

This PR adds reason label to kube_deployment_status_condition metrics.

It's necessary to distinguish between Progressing Deployment and Complete Deployment .

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
no changes in cardinality

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1991

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 4, 2025
@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 4, 2025
metric.LabelValues = append([]string{string(c.Type)}, metric.LabelValues...)
reason := c.Reason
if _, ok := allowedDeploymentReasons[reason]; !ok {
reason = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be empty? or should this be "unknown"

CC: @rexagod

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with an empty string for cleaner queries, but I'm open to changing it if you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it depends, is the reason ever empty? then we could use unknown to differ between an empty reason and something we don't recognize.

if the reason field is never empty, this approach is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah right, seems like reason field can be empty, I've changed it to unknown, thanks for pointing out!

@dgrisonnet
Copy link
Member

/assign @mrueg
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 7, 2025
@Rishab87
Copy link
Contributor Author

@mrueg I've made the changes, can you have a look again?

metric.LabelKeys = []string{"condition", "status"}
metric.LabelValues = append([]string{string(c.Type)}, metric.LabelValues...)
reason := c.Reason
if _, ok := allowedDeploymentReasons[reason]; !ok {
Copy link
Member

@mrueg mrueg Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's empty, will it still be unknown?
Can you create a test with the reason field being empty as well as with one test with a non allowed deployment reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was the case earlier, fixed it if its empty then it will remain empty and will show unknown if reason is not in the allowed list, also added the tests for both cases.

@Rishab87
Copy link
Contributor Author

@mrueg made changes, can you have another look?

@@ -183,8 +183,10 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
metric := m

reason := c.Reason
if _, ok := allowedDeploymentReasons[reason]; !ok {
reason = "unknown"
if reason != "" {
Copy link
Member

@mrueg mrueg Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add "" to the allowedDeploymentReasons instead?

Copy link
Contributor Author

@Rishab87 Rishab87 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, added it

@Rishab87
Copy link
Contributor Author

@mrueg I've addressed the reviews, can you look again?

Comment on lines 44 to 46
var (
allowedDeploymentReasons = map[string]struct{}{
"MinimumReplicasAvailable": {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at these strings again
https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/deployment/util/deployment_util.go#L67

Can we refer to these here instead and create a complete list based on what's available in deployment_util.go?

Suggested change
var (
allowedDeploymentReasons = map[string]struct{}{
"MinimumReplicasAvailable": {},
import deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
var (
allowedDeploymentReasons = map[string]struct{}{
deploymentutil.MinimumReplicasAvailable: {},

Copy link
Contributor Author

@Rishab87 Rishab87 Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrueg, When I'm trying to:

go get k8s.io/kubernetes/pkg/controller/deployment/util

I'm getting this:

k8s.io/controller-manager/pkg/features: reading k8s.io/controller-manager/go.mod at revision v0.0.0: unknown revision v0.0.0

Is this a good idea to use internal k8s packages directly? should I directly use strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, you're right!

Can you copy all other reasons over as a string and add a comment that they are taken from deployment_utils.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrueg thanks for the review, made the changes

@CatherineF-dev
Copy link
Contributor

/lgtm
/hold
@mrueg for the final review

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 13, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 13, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CatherineF-dev, Rishab87

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 13, 2025
@CatherineF-dev
Copy link
Contributor

/triage accepted

"DeploymentPaused": {},
"DeploymentResumed": {},
"MinimumReplicasAvailable": {},
"MinimumReplicasUnavailable": {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the "" if it's unavailable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include reason label to the kube_deployment_status_condition metric
5 participants